package com.lazydong.gui_gateway.route;

import com.lazydong.gui_gateway.model.ServiceIpAddr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private DynamicRouteComponent dynamicRouteComponent;

    @GetMapping("/addRoute")
    public Boolean addRoute() {
        ServiceIpAddr serviceIpAddr = new ServiceIpAddr();
        serviceIpAddr.setPredicate("/**");
        serviceIpAddr.setServiceId("environment");
        serviceIpAddr.setServiceName("environment");
        serviceIpAddr.setName("开发环境");
        serviceIpAddr.setAddr("http://127.0.0.1:8888");
        dynamicRouteComponent.routeChangeEvent(serviceIpAddr);
        return true;
    }

    @GetMapping("/deleteRoute")
    public Boolean deleteRoute() {
        ServiceIpAddr serviceIpAddr = new ServiceIpAddr();
        serviceIpAddr.setPredicate("/**");
        serviceIpAddr.setServiceId("environment");
        serviceIpAddr.setServiceName("environment");
        serviceIpAddr.setName("");
        serviceIpAddr.setAddr("");
        dynamicRouteComponent.routeChangeEvent(serviceIpAddr);
        return true;
    }

    @GetMapping("/updateRoute")
    public Boolean updateRoute() {
        ServiceIpAddr serviceIpAddr = new ServiceIpAddr();
        serviceIpAddr.setPredicate("/**");
        serviceIpAddr.setServiceId("environment");
        serviceIpAddr.setServiceName("environment");
        serviceIpAddr.setName("测试环境");
        serviceIpAddr.setAddr("http://127.0.0.1:9999");
        dynamicRouteComponent.routeChangeEvent(serviceIpAddr);
        return true;
    }
}
